package com.yim.string;

import java.util.Random;

/**
 * 随机截取指定长度的字符串
 * @filename RandomString.java
 * @author 陈志延
 * @datetime 2013-11-22上午9:32:36
 * @version
 */
public class RandomString {
	
	public static String randomString(String string,int length){
		StringBuffer sb = new StringBuffer();
		Random random = new Random();
		for (int i = 0; i < length; i++) {
			int num = random.nextInt(string.length());
			sb.append(string.charAt(num));
		}
		return sb.toString();
	}
}
